"""
asyncio
"""

import asyncio, time


async def work(m):
    print(f"work: {m}")
    # await asyncio.sleep(2)


now = time.time

start = now()
# 获取事件循环
loop = asyncio.get_event_loop()

# 创建协程列表
tasks = [loop.create_task(work(n)) for n in range(20, 25)]

print(tasks)

# 等待所有任务完成
loop.run_until_complete(asyncio.gather(*tasks))

print(tasks)
# coroutine = work(20)

# loop.run_until_complete(coroutine)
print(f"time is : {now() - start}")

# 关闭事件循环
loop.close()

print("同步===========================")


def work1(m):
    print(f"work: {m}")
    # time.sleep(2)


start = now()
for n in range(20, 25):
    work1(n)
print(f"time is : {now() - start}")
